//package com.xywy.start;
//
//import java.math.BigInteger;
//import java.util.List;
//
//import android.bluetooth.BluetoothGatt;
//import android.bluetooth.BluetoothGattCharacteristic;
//import android.bluetooth.BluetoothGattService;
//import android.content.BroadcastReceiver;
//import android.content.Context;
//import android.content.Intent;
//import android.content.IntentFilter;
//import android.content.SharedPreferences;
//import android.content.SharedPreferences.Editor;
//import android.os.Bundle;
//import android.os.Handler;
//import android.util.Log;
//import android.view.animation.Animation;
//import android.view.animation.TranslateAnimation;
//import android.widget.ImageView;
//import android.widget.TextView;
//import android.widget.Toast;
//
//import com.xywy.R;
//import com.xywy.common.BaseActivity;
//import com.xywy.common.FragmentMainActivity;
////import com.xywy.common.util.ble.util.BluetoothLeGattUtils;
//import com.xywy.common.util.ble.util.BluetoothUtils;
////import com.xywy.common.widget.GuidiWeightScaleView;
//import com.xywy.common.widget.TitleBar;
//
//public class ConnectWeightActivity extends BaseActivity {
//	public static final String TAG = "ConnectWeightActivity";
//	public static final String EXTRAS_DEVICE_ADDRESS = "DEVICE_ADDRESS";
//	public static final String USER_WEIGHT_DATA_1 = "data1";
//	public static final String USER_WEIGHT_DATA_2 = "data2";
//
//	private final int AOTU_SEND_ORDER = 1;
//	private final int HAND_SEND_ORDER = 2;
//
//	private BluetoothUtils bu; //蓝牙工具类
//	private BluetoothGatt gatt;//蓝牙通讯协议
////	private BluetoothLeGattUtils gattUtil;//蓝牙通讯工具类；
//	private BluetoothGattCharacteristic curCharacteristic = null;//当前通道；
//
//	private SharedPreferences sp; //模拟保存当前用户的基本数据
//	private Editor editor;// 保存当前数据：
//
////	private GuidiWeightScaleView view_curdata; // 现实重量
//	private ImageView iv_foot; // 脚的动画；
//
//	private boolean mConnected; // 当前连接状态
//	private int curDeviceState = 0;// 0 默认。 1自动发送 ，2，只能手动发送。
//	private String curAddress = null;
//	private List<BluetoothGattService> gattServices;
//
//	/* 测量结束后的 */
//	private byte[] resultData_1; // 第一组数据
//	private byte[] resultData_2; // 第二组数据
//
//	Handler handler = new Handler() {
//		public void handleMessage(android.os.Message msg) {
//			switch (msg.what) {
//			case BluetoothUtils.GET_USER_INFO_1:
//				resultData_1 = (byte[]) msg.obj;
//				break;
//			case BluetoothUtils.GET_USER_INFO_2:
//				resultData_2 = (byte[]) msg.obj;
//				Intent intent = new Intent(ConnectWeightActivity.this,
//						FragmentMainActivity.class);
//				intent.putExtra(USER_WEIGHT_DATA_1, resultData_1);
//				intent.putExtra(USER_WEIGHT_DATA_2, resultData_2);
//				startActivity(intent);
//			}
//		};
//	};
//
//	@Override
//	protected void onCreate(Bundle savedInstanceState) {
//		super.onCreate(savedInstanceState);
//		setContentView(R.layout.start_conn_weight);
//		this.preInit();
//		initTitle();
//		this.initView();
//	}
//
//	private void initTitle() {
//		TitleBar titleBar = (TitleBar) findViewById(R.id.title_bar);
//		titleBar.onClickBack(this);
//		TextView tvTitle = titleBar.getTitle();
//		tvTitle.setText(getString(R.string.tv_start_height));
//	}
//
//	@Override
//	protected void onResume() {
//		super.onResume();
//		registerReceiver(mGattUpdateReceiver, makeGattUpdateIntentFilter());
////		gattUtil.connect(curAddress); // 连接称
//
//	}
//
//	@Override
//	protected void onPause() {
//		super.onPause();
//		unregisterReceiver(mGattUpdateReceiver);
//	}
//
//	@Override
//	public void preInit() {
//		sp = getSharedPreferences("config", MODE_PRIVATE);
//		editor = sp.edit();
//		if (getIntent().hasExtra(EXTRAS_DEVICE_ADDRESS)) {
//			curAddress = getIntent().getStringExtra(EXTRAS_DEVICE_ADDRESS);
//		}
//
//		// TODO:
////		bu = BluetoothUtils.getInstance();
////		bu.init(ConnectWeightActivity.this, handler);
////		gattUtil = bu.getBLEServiceUtil();
//		editor.putInt("age", 30);
//		editor.putInt("height", 1750);
//		editor.putInt("sex", 1);
//		editor.commit();
//
//	}
//
//	@Override
//	public void loadData() {
//
//	}
//
//	/**
//	 * 图片：脚的动画
//	 * 
//	 * @param iv
//	 */
//	private void began(ImageView iv) {
//		TranslateAnimation animation = new TranslateAnimation(0, 0, -50, 50);
//		animation.setDuration(1000);// 设置动画持续时间
//		animation.setRepeatCount(999);// 设置重复次数
//		animation.setRepeatMode(Animation.REVERSE);// 设置反方向执行
//		iv.setAnimation(animation);
//		animation.startNow();
//	}
//
//	@Override
//	public void initView() {
////		view_curdata = (GuidiWeightScaleView) findViewById(R.id.view_curdata);
////		iv_foot = (ImageView) findViewById(R.id.iv_foot);
//		began(iv_foot);
//	}
//
//	int i = 0;
//	/*
//	 * 和蓝牙设备进行交互的广播
//	 */
//	private final BroadcastReceiver mGattUpdateReceiver = new BroadcastReceiver() {
//		@Override
//		public void onReceive(Context context, Intent intent) {
////			final String action = intent.getAction();
//////			if (BluetoothLeGattUtils.ACTION_GATT_CONNECTED.equals(action)) { // 连接时
////				mConnected = true;
////				connected();
//////			} else if (BluetoothLeGattUtils.ACTION_GATT_DISCONNECTED
////					.equals(action)) {// 断开连接时
////				mConnected = false;
////				disconnected();
//////			} else if (BluetoothLeGattUtils.ACTION_GATT_SERVICES_DISCOVERED
////					.equals(action)) {
////				// 只会再连接设备的时候触发一次
////				getServices();
////			} else if (BluetoothLeGattUtils.ACTION_DATA_AVAILABLE
////					.equals(action)) {
////				curCharacteristic = gattUtil.getCurCharacterisitc();
////				String charr = curCharacteristic.getUuid().toString();
////				if (null == charr) {
////					return;
////				} else if (charr.equals(BluetoothUtils.BLE_DEVICE_INFO_CHAR)) { // 获取SystemID
////					Log.d(TAG, "当前的设备SystemID是 ＝ "
////							+ curCharacteristic.getUuid().toString());
////					Toast.makeText(ConnectWeightActivity.this,
////							"切换通道为：SystemID", Toast.LENGTH_LONG).show();
////				} else if (charr.equals(BluetoothUtils.BLE_SWAP_DATA_CHAR)) {/* 交换数据 */
////					Toast.makeText(ConnectWeightActivity.this,
////							"切换通道为：控制通道，可以发送指令", Toast.LENGTH_LONG).show();
////
////					if (curCharacteristic != null) {
////						byte[] weight = curCharacteristic.getValue();
////						if (weight[1] == (byte) 0x07) {
////							// 此时的状态是当前的重量
////							view_curdata.setCurText(getdata(weight[5],
////									weight[6]) / 10 + "kg");
////						}
////						// 08 07 02 B0 01 00 44
////						if (gatt == null) {
////							gatt = gattUtil.getmBluetoothGatt();
////						}
////						if (curDeviceState == AOTU_SEND_ORDER) {
////							send_Order();
////							curDeviceState = HAND_SEND_ORDER;
////						}
////						bu.updateUserInfo(gatt, curCharacteristic);
////						if (weight[1] == 0x11) {
////							Toast.makeText(ConnectWeightActivity.this,
////									"数据已经稳定", Toast.LENGTH_LONG).show();
////						}
////					}
////				}
////			}
//		}
//
//		/**
//		 * 显示
//		 * 
//		 * @param string
//		 */
//		private void displayData(byte[] weight) {
//			StringBuilder sb = new StringBuilder();
//			for (byte byteChar : weight) {
//				sb.append(String.format("%02X ", byteChar));
//			}
////			view_curdata.setCurText(sb.toString());
//		}
//
//		/**
//		 * 处理16进制数据
//		 * 
//		 * @param data
//		 * @return
//		 */
//		private float getdata(byte... data) {
//			BigInteger bigNum = new BigInteger(data);
//			float intNum = Float.parseFloat(bigNum.intValue() + "");
//			return intNum;
//		}
//	};
//
//	/**
//	 * 开始测量命令：
//	 */
//	private void send_Order() {
//		bu.excuteOrder(gatt, curCharacteristic);
//		Toast.makeText(ConnectWeightActivity.this, "请您踩到称上！", Toast.LENGTH_LONG)
//				.show();
//	}
//
//	/**
//	 * 未连接动作
//	 */
//	private void disconnected() {
//
//	}
//
//	/**
//	 * 连接后动作
//	 */
//	private void connected() {
//
//	}
//
//	/**
//	 * 获取设备gatt Services
//	 */
//	private void getServices() {
////		gatt = gattUtil.getmBluetoothGatt();
//		gattServices = gatt.getServices();
//		getSystemID(gattServices);
//		getConnPort(gattServices);
//	}
//
//	/**
//	 * 获取当前设备的SystemID
//	 * 
//	 * @param gattServices
//	 */
//	private void getSystemID(List<BluetoothGattService> gattServices) {
////		bu.getSystemID(gattServices);
//		curDeviceState = 1;
//	}
//
//	/**
//	 * 连接通讯接口
//	 */
//	private void getConnPort(List<BluetoothGattService> gattServices) {
////		bu.getBLEPort(gattServices);
//	}
//
//	/**
//	 * 广播过滤器 蓝牙状态的处理
//	 * 
//	 * @return
//	 */
//	private static IntentFilter makeGattUpdateIntentFilter() {
//		final IntentFilter intentFilter = new IntentFilter();
////		intentFilter.addAction(、uetoothLeGattUtils.ACTION_DATA_AVAILABLE);
//		return intentFilter;
//	}
//
//	@Override
//	protected void onDestroy() {
//		super.onDestroy();
//
//	}
//
//}
